package com.yuntian.controller.user;


import com.yuntian.Dto.OrderPageQueryDto;
import com.yuntian.entity.Order;
import com.yuntian.result.PageResult;
import com.yuntian.result.Result;
import com.yuntian.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController("userOrderController")
@RequestMapping("/user/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 查询所有订单
     */
    @GetMapping("/all")
    public Result<PageResult> getAllOrders(OrderPageQueryDto orderPageQueryDto) {
        PageResult pageResult = orderService.selectAllOrder(orderPageQueryDto);
        return Result.success(pageResult);
    }

    /**
     * 创建订单
     */
    @PostMapping("/create")
    public Result createOrder(@RequestBody Order order) {
        orderService.createOrder(order);
        return Result.success();
    }

    /**
     * 获取订单详情
     */
    @GetMapping("/{orderId}")
    public Result<Order> getOrderDetail(@PathVariable Integer orderId) {
        Order order = orderService.getOrderDetail(orderId);
            return Result.success(order);
    }

    /**
     * 确认订单信息
     */
    @GetMapping("/confirm/{userId}")
    public Result<Map<String, Object>> confirmOrder(@PathVariable Long userId) {
        Map<String, Object> result = orderService.confirmOrder(userId);
        return Result.success(result);
    }
    //取消订单
    @PutMapping("/cancel")
    public Result cancel(Integer orderId){
        orderService.cancel(orderId);
        return Result.success();
    }
}
